<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
  
  <head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="manager/css/font.css">
    <link rel="stylesheet" href="manager/css/xadmin.css">
      <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
      <script src="https://cdn.bootcss.com/jquery.form/3.51/jquery.form.js"></script>
    <script type="text/javascript" src="manager/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="manager/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  
  <body>
    <div class="x-body layui-anim layui-anim-up">
        <form class="layui-form" enctype="multipart/form-data">
            <input type="hidden" name="pc_id" th:value="${pc.pc_id}" />
          <div class="layui-form-item">
              <label class="layui-form-label">
                  <span class="x-red">*</span>产品类型名
              </label>
              <div class="layui-input-inline">
                  <input type="text" name="pc_name" required="" lay-verify="pass"
                  autocomplete="off" th:value="${pc.pc_name}" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  1到30个字符
              </div>
          </div>

          <div class="layui-form-item">
              <label class="layui-form-label">
                  <span class="x-red">*</span>产品类型描述
              </label>
              <div class="layui-input-inline">
                  <input type="text" name="pc_desc" required="" lay-verify="pass"
                  autocomplete="off" th:value="${pc.pc_desc}" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  1到30个字符
              </div>
          </div>
          <div class="layui-form-item">
                  产品类型图片:
              <input id="myfiles" onchange="loadImg(event)" type="file" name="myfile" />
              <img style="width: 100px;width: 100px;" id="imgs" th:src="${pc.pc_image}">
          </div>
          <div class="layui-form-item">
              <label class="layui-form-label">
              </label>
              <button  class="layui-btn" lay-filter="add" lay-submit="">
                  修改
              </button>
          </div>
      </form>
    </div>
    <script>
        function loadImg(e){
            console.info(e.target.files[0]);//图片文件
            console.log(e.target.value);//这个也是文件的路径和上面的dom.value是一样的
            var reader = new FileReader();
            reader.onload = (function (file) {
                return function (e) {
                    console.info(this.result); //这个就是base64的数据了
                    document.getElementById("imgs").src = this.result;
                };
            })(e.target.files[0]);
            reader.readAsDataURL(e.target.files[0]);
        }
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
          var form = layui.form
          ,layer = layui.layer;
        
          //自定义验证规则
          form.verify({

            pass: function (value) {
                if(value.length<1||value.length>30){
                    return '输入内容不符合规则';
                }
            }
          });

          //监听提交
          form.on('submit(add)', function(data){
                //发异步，把数据提交给php
                $("form").ajaxSubmit({
                    url: "updProductCategory",
                    type: "post",
                    success: function (result) {
                        if (result.result == "0000") {
                            layer.alert("修改成功", {icon: 6}, function () {
                                // 获得frame索引
                                var index = parent.layer.getFrameIndex(window.name);
                                //关闭当前frame
                                window.parent.location.reload();
                                parent.layer.close(index);
                            });
                        } else {
                            layer.msg(result.resultMsg, {icon: 1, time: 1000});
                        }
                    },
                    dataType: "json"
                })
            return false;
          });
        });
    </script>
  </body>

</html>